#-*- coding:utf-8 -*-
import re
from django.contrib.auth.models import User
from django.core.exceptions import ObjectDoesNotExist
from django import forms
from django.forms import ModelForm

from master.models import *

class LoginForm(forms.Form):
    username = forms.CharField()
    password = forms.CharField(widget=forms.PasswordInput, label="Your Password" )
    
    

class ProjectCreateForm(forms.ModelForm):
    '''삭제 예정'''
    
    """
    class Meta:
        model = Project

    def __init__(self, *args, **kwargs):
            logging.debug("^^^^^^^^^^^^^^^^^^^^^^^")
            house_code = kwargs.pop('house_code','100')
            logging.debug(house_code)
        
            super(ProjectCreateForm, self).__init__(*args, **kwargs)
            #self.fields['super_code'].required = False
            
            self.fields['project_code'].label = '회사코드'
            
            instance = getattr(self, 'instance', None)
            if instance and instance.id:
                self.fields['house_code'].widget.attrs['readonly'] = 'readonly'
                self.fields['code'].widget.attrs['readonly'] = 'readonly'
    """            


class CodeCreateForm(forms.ModelForm):
    #house_code = forms.CharField(initial='100', min_length=3, label='group code')
    #code = forms.CharField(min_length=3, label='코드')
    #description = forms.CharField(max_length=200)
    #sort_seq = forms.CharField(initial=1)
    #memo = forms.CharField(widget=forms.Textarea)
    #used = forms.BooleanField(initial=False, required=False)
    
    """
    foo= forms.CharField(required=False)
    
    def __init__(self, *args, **kwargs):
            logging.debug("^^^^^^^^^^^^^^^^^^^^^^^")
            house_code = kwargs.pop('house_code','100')
            logging.debug(house_code)
        
            super(CodeCreateForm, self).__init__(*args, **kwargs)
            self.fields['super_code'].required = False
            
            instance = getattr(self, 'instance', None)
            if instance and instance.id:
                self.fields['house_code'].widget.attrs['readonly'] = 'readonly'
                self.fields['code'].widget.attrs['readonly'] = 'readonly'
                
                #logging.info(self.fields['house_code'].widget.attrs)
                #self.fields['sku'].widget.attrs['disabled'] = 'disabled'
                #self.fields[field].widget.attrs['readonly'] = True

            self.fields['super_code'].queryset = MasterCode.objects.filter(
                        house_code=house_code)
                
                
            logging.debug("^^^^^^^^^^^^^^^^^^^^^^^")
                
    
    class Meta:
        model = MasterCode
        '''
        widgets = {
            'house_code':forms.TextInput(attrs={}),
        }
        '''
        #exclude = ('super_code',)
        
    """    
    
class UserInformationForm(forms.ModelForm):
    
    class Meta:
        model = UserProfiles
        fields = ('picture',)
        #exclude = ('picture',)

        
    #picture = forms.ImageField()
    
    
    